#include <iostream>
#include <stdio.h>
#include <set>
#include <cstring>
using namespace std;
int a[55];
int size[55];
set<int> s[55];
int n;
int res,ask;
int INF;
void DFS(int zz, int path) {
	if (zz==0 && a[zz]==ask && path<res) res=path;
	cout<<zz<<" "<<a[zz]<<" "<<path<<endl;
	cout<<"--------"<<endl;
	for (int i=0; i<n; ++i) cout<<a[i]<<" ";
	cout<<endl;
	if (a[zz]==0) return ;
	if (s[zz].count(a[zz])) return;
	s[zz].insert(a[zz]);
	for (int i=0; i<n; ++i) {
		if (i==zz) continue;
		if (size[i]-a[i]>=a[zz]) {
			int tmp1=a[zz], tmp2=a[i];
			a[zz]=0; a[i]=a[i]+tmp1;
			for (int j=0; j<n; ++j) DFS(j, path+tmp1);
			a[zz]=tmp1; a[i]=tmp2;
		}
		else {
			int tmp1=a[zz], tmp2=a[i], tmp3=size[i]-a[i];
			a[zz]=a[zz]-tmp3; a[i]=size[i];
			for (int j=0; j<n; ++j) DFS(j, path+tmp3);
			a[zz]=tmp1; a[i]=tmp2;
		}
	}
}
void MyDFS() {
	for (int i=0; i<55; ++i) {
		s[i].clear();
	}
	memset(&res, 0x3f, sizeof(res));
	DFS(0, 0);
}
int main() {
//	freopen("in.txt", "r", stdin);
	memset(&INF, 0x3f, sizeof(INF));
	cin.sync_with_stdio(false);
	while (cin>>n) {
		for (int i=0; i<n; ++i) cin>>size[i];
		cin>>ask;
		memset(a, 0, sizeof(a));
		a[0]=size[0];
		MyDFS();
		if (res==INF) cout<<"impossible"<<endl;
		else cout<<res<<endl;
	}
	return 0;
}
